/**
 * Copyright(c) 2014 Xunton Solutions
 *
 * History:
 *   15-1-9 上午11:21 Created by dwzhang
 */
package com.jade.framework.base.vfile.impl;

import java.util.Map;
import javax.inject.Named;

import com.jade.framework.base.util.Parameters;
import com.jade.framework.base.vfile.StorageStrategy;
import com.jade.framework.base.vfile.VFileManager;
import com.jade.framework.base.vfile.VFileStorage;

/**
 * 缺省的文件存储器。
 *
 * @author <a href="mailto:dwzhang@xunton.com">dwzhang</a> 
 * @version 1.0 15-1-9 上午11:21
 */
@Named ("system_vfileStorage")
public class DefaultFileStorage
        implements VFileStorage
{
    private Map<String, VFileManager> managerMap;
    private VFileManager defaultManager;
    private StorageStrategy strategy;

    public void setManagerMap(Map<String, VFileManager> managerMap)
    {
        this.managerMap = managerMap;
    }

    public void setDefaultManager(VFileManager defaultManager)
    {
        this.defaultManager = defaultManager;
    }

    public void setStrategy(StorageStrategy strategy)
    {
        this.strategy = strategy;
    }

    @Override
    public VFileManager getFileManager(String dataType)
    {
        return getFileManager(dataType, null);
    }

    @Override
    public VFileManager getFileManager(String dataType, Parameters parameters)
    {
        VFileManager manager = null;
        if (strategy != null) {
            manager = managerMap.get(strategy.getFileManager(dataType, parameters));
        }
        if (manager == null) {
            manager = defaultManager;
        }
        return manager;
    }
}
